//
//  CommonView.m
//  TheRoadAD
//
//  Created by baixue on 16/8/12.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "CommonView.h"
#import "BSSquareCell.h"

#define  margin  5
#define  cellWH  (Screen_Width - 10*5)/3
static NSString *const ID = @"BSSquareCell";
@implementation CommonView


-(id)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setUpFooterViewWithframe:frame];
    }
    return self;
}

-(void)setUpFooterViewWithframe:(CGRect)frame{
    // 1.创建流水布局
    UICollectionViewFlowLayout *layout = ({
        
        // 1.创建流水布局
        UICollectionViewFlowLayout *layout =  [[UICollectionViewFlowLayout alloc] init];
        
        // 2.设置流水布局属性
        
        // 2.1设置cell尺寸
        layout.itemSize = CGSizeMake(cellWH, cellWH);
        
        // 2.2 设置cell之间间距
        layout.minimumLineSpacing = margin;
        
        layout;
    });
    
    // 2.创建UICollectionView
    UICollectionView *collectionView = ({
        
        // 1.创建UICollectionView
        UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:frame collectionViewLayout:layout];
        
        
        // 2.设置数据源 -> 要UICollectionView展示数据
        collectionView.dataSource = self;
        collectionView.delegate = self;
        collectionView.showsHorizontalScrollIndicator = YES;
        
        // 3. 注册cell
        [collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([BSSquareCell class]) bundle:nil] forCellWithReuseIdentifier:ID];
        
        // 4.不允许collectionView滚动
        // 取消弹簧效果
        //        collectionView.bounces = NO;
        collectionView.scrollEnabled = NO;
        collectionView.backgroundColor = [UIColor whiteColor];
        
        
        collectionView;
        
    });
    
    _collectionView = collectionView;
    
    // 3.设置collectionView为tableView的footView
    // 设置tableView的footView,高度由我们自己决定,宽度,位置都是控制不了
    [self addSubview:collectionView];
    
    
    
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    
    return UIEdgeInsetsMake(0, 10, 0, 10);
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    BSSquareCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
    
    //     获取模型
    //     BSSquareItem *item = self.squareList[indexPath.row];
    //
    //     cell.item = item;
    
    return cell;
}

//每个item的点击事件
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    NSLog(@"gdj");
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 9;
    
    
}



@end
